﻿#include "frminputnumber.h"
#include "ui_frminputnumber.h"
#include "frminput2019.h"

frmInputNumber::frmInputNumber(QWidget *parent) : QWidget(parent), ui(new Ui::frmInputNumber)
{
    ui->setupUi(this);
    retranslateUiSlot();
}

frmInputNumber::~frmInputNumber()
{
    delete ui;
}

void frmInputNumber::setInput(frmInput2019 *input)
{
    this->input = input;
}

void frmInputNumber::setBtns(QList<QPushButton *> btns)
{
    this->btns = btns;
}

void frmInputNumber::setSpacing(int spacing)
{
    ui->widgetNumberLeft->layout()->setSpacing(spacing);
    ui->widgetNumberRight->layout()->setSpacing(spacing);
}

void frmInputNumber::initClicked()
{
    //关联信号槽 直接用主界面的按钮
    if (this->btns.count() >= 4) {
        connect(ui->btnDelete, SIGNAL(clicked(bool)), this->btns.at(0), SLOT(click()));
        connect(ui->btnSpace, SIGNAL(clicked(bool)), this->btns.at(1), SLOT(click()));
        connect(ui->btnEnter, SIGNAL(clicked(bool)), this->btns.at(2), SLOT(click()));
        connect(ui->btnClose, SIGNAL(clicked(bool)), this->btns.at(3), SLOT(click()));
    }

    QList<QPushButton *> btns;
    btns = ui->widgetNumber->findChildren<QPushButton *>();
    input->initBtn(btns);

    btns = ui->widgetNumberLeft->findChildren<QPushButton *>();
    foreach (QPushButton *btn, btns) {
        connect(btn, SIGNAL(clicked(bool)), this, SLOT(btnClicked()));
    }
}

void frmInputNumber::btnClicked()
{
    QPushButton *btn = (QPushButton *)sender();
    input->sendEvent(4, btn->text());
}

void frmInputNumber::setStyleName(const QString &styleName)
{
    QString strDelete = QString(":/image/btn_%1_%2.png").arg("delete").arg(styleName);
    QString strEnter = QString(":/image/btn_%1_%2.png").arg("enter").arg(styleName);
    QString strClose = QString(":/image/btn_%1_%2.png").arg("close").arg(styleName);
    ui->btnDelete->setIcon(QIcon(strDelete));
    ui->btnEnter->setIcon(QIcon(strEnter));
    ui->btnClose->setIcon(QIcon(strClose));
    ui->btnDelete->setText("");
    ui->btnEnter->setText("");
    ui->btnClose->setText("");
}

void frmInputNumber::retranslateUiSlot()
{
    ui->retranslateUi(this);
    ui->btnClose->setHidden(true);
    this->setStyleName("white");
}
